package com.fangzhi.controller;

import com.fangzhi.service.CommissionService;
import com.fangzhi.service.OrdersService;
import com.fangzhi.utils.ResponseResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.time.YearMonth;

@RestController
@RequestMapping("/commission")
public class CommissionController {

    @Autowired
    private CommissionService commissionService;
    @Autowired
    private OrdersService ordersService;

    /**
     * 销售额
     * @param time
     * @return
     */
    @GetMapping("/salesPrice")
    public ResponseResult salesPrice(@RequestParam @DateTimeFormat(pattern = "yyyy-MM") YearMonth time){
        return ordersService.salesPrice(time);
    }

    /**
     * 订单数
     * @param time
     * @return
     */
    @GetMapping("/orderCount")
    public ResponseResult orderCount(@RequestParam @DateTimeFormat(pattern = "yyyy-MM") YearMonth time){
        return ordersService.orderCount(time);
    }

    /**
     * 首页排行榜
     * @param time
     * @return
     */
    @GetMapping("/top")
    public ResponseResult top(@RequestParam @DateTimeFormat(pattern = "yyyy-MM") YearMonth time){
        return commissionService.top(time);
    }

}
